<%@ page language="java" import="okhttp3.*" pageEncoding="UTF-8" %>
<%@ page import="org.json.JSONArray" %>
<%@ page import="org.json.JSONException" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.xuch.action.bean.*" %>
<%@ page import="weaver.interfaces.xuch.action.util.CurrencyUtil" %>
<%@ page import="weaver.interfaces.xuch.action.util.Soap_Util" %>
<%@ page import="weaver.interfaces.xuch.action.util.Upload_Util" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%--流程退回调用QMS接口--%>
<%
    out.print(">>>>>>>>>>>>>>>>>>>>>测试页面>>>>>>>>>>>>>>>>>>>>><br/>");
    try {
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        String fpdmParam = Util.null2String(request.getParameter("fpdm"));

        if ("".equals(fpdmParam)) {
            String sql = "select * from uf_fpxxlc where sfybcswpt is null";
            out.print(">>>>>>>>测试页面>>>>>>>>>>>sql=" + sql + "<br/>");
            rs.execute(sql);
        } else {
            String sql = "select * from uf_fpxxlc where fpdm='" + fpdmParam + "'";
            out.print(">>>>>>>>测试页面>>>>>>>>>>>sql=" + sql + "<br/>");
            rs.execute(sql);
        }
        out.print(">>>>>>>>测试页面>>>>>>>>>>>fpdm=" + fpdmParam + "<br/>");
        String sj = DateUtil.getFullDate();
        Upload_Util uu = new Upload_Util();
        Soap_Util su = new Soap_Util();
        while (rs.next()) {
            String requestid = Util.null2String(rs.getString("lcrequestid"));
            String id = Util.null2String(rs.getString("id"));
            String sm = Util.null2String(rs.getString("sm"));
            String lcbhpch = Util.null2String(rs.getString("lcbhpch"));// 流程编号
            String qsr = Util.null2String(rs.getString("qsrpzzdrgh"));// 签收人
            String rzr = Util.null2String(rs.getString("rzrpzzdrgh"));// 入账人
            String sqr = getWorkcode(Util.null2String(rs.getString("sqr")));// 申请人
            String fpdmss = Util.null2String(rs.getString("fpdm"));// 发票代码id
            String ywlx = Util.null2String(rs.getString("ywlx"));// 业务类型
            String fpdms[] = fpdmss.split(",");
            if (!sm.equals("")) {
                rs1.execute("select SELECTNAME from workflow_selectitem where fieldid = 35423 and SELECTVALUE = " + sm);
                rs1.next();
                sm = Util.null2String(rs1.getString("SELECTNAME"));
            }
            for (int ii = 0; ii < fpdms.length; ii++) {
                String fpdm = fpdms[ii];
                HashMap<String, String> fpxx = getAllFanInfo(fpdm);
                out.print(">>>>>>>>测试页面>>>>>>>>>>>fpxx=" + fpxx + "<br/>");
                Map<String, String> sap_map = getSAPInfo(requestid);
                if (sap_map.get("sapcode").equals("")) {
                    continue;
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>fpxx=" + fpxx + "<br/>");
                JSONObject billInfo = new JSONObject();
                try {
                    String token = su.getToken();
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>token=" + token + "<br/>");
                    String cloudId = fpxx.get("cloudId");
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>cloudId=" + cloudId + "<br/>");
                    billInfo = getAllInfoFromHttp(cloudId,token);
//					bb.writeLog("billifo::" + billInfo.toString() + ":::::::::::::::::::::::");
                } catch (Exception e1) {
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>Http请求异常<br/>");
                    e1.printStackTrace();
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>billInfo=" + billInfo + "<br/>");
                JSONObject extJson = new JSONObject();
                try {
                    extJson = new JSONObject(billInfo.get("ext").toString());
                } catch (JSONException e4) {
                    // TODO Auto-generated catch block
                    e4.printStackTrace();
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>extJson=" + extJson + "<br/>");
                JSONObject vehicleDetail = new JSONObject();

                if (extJson.has("vehicleDetail")) {
                    try {
                        vehicleDetail = extJson.getJSONObject("vehicleDetail");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>vehicleDetail=" + vehicleDetail + "<br/>");
                JSONArray products = new JSONArray();
                if (extJson.has("products")) {
                    try {
                        products = extJson.getJSONArray("products");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>products=" + products + "<br/>");
                JSONObject comm_info = new JSONObject();
                try {
                    comm_info = new JSONObject(billInfo.getString("comm_info"));
                } catch (JSONException e3) {
                    // TODO Auto-generated catch block
                    e3.printStackTrace();
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>comm_info=" + comm_info + "<br/>");
                JSONObject payer = new JSONObject();
                try {
                    payer = new JSONObject(comm_info.getString("payer"));
                } catch (JSONException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                out.print(">>>>>>>>测试页面>>>>>>>>>>>payer=" + payer + "<br/>");
                out.print(">>>>>>>>测试页面>>>>>>>>>>>invoicetype=" + setFplx(fpxx.get("invoicetype")) + "<br/>");
                // 增值税发票
                if (!setFplx(fpxx.get("invoicetype")).equals("")) {
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>增值税发票<br/>");
                    Bill bill = new Bill();// 发票类
                    // 发票信息
                    Fp fp = new Fp();
                    fp.setLot_no(lcbhpch);
                    fp.setQsr(qsr);
                    fp.setQssj(sj);
                    fp.setQszt("1");
                    fp.setSfts("1");
                    fp.setTsmg("推送成功");
                    fp.setRzzt("1");
                    fp.setRzr(rzr);
                    fp.setCymsg("查验成功");
                    fp.setCysfcg("0");
                    fp.setInv_code(fpxx.get("invoicecode"));
                    fp.setInv_num(fpxx.get("invoicenumber"));
                    fp.setKprq(fpxx.get("billingdate"));
                    // 获取销方信息
                    HashMap<String, String> xfxx = getAllDtlInfo(fpdm);
                    fp.setSell_name(fpxx.get("seller"));
                    fp.setSell_tax_num(fpxx.get("salestaxno"));
                    fp.setSell_bank_acc(xfxx.get("salesBank"));
                    fp.setSell_add_tel(xfxx.get("sellerAddress"));
                    fp.setYwlx(ywlx);
                    fp.setC_fpzt("0");
                    fp.setSfocr("1");
                    fp.setFplx(setFplx(fpxx.get("invoicetype")));
                    fp.setRisk_level("0");
                    fp.setMoney(fpxx.get("pricewithouttax"));
                    fp.setTax_money(fpxx.get("tax"));
                    fp.setTax_total(fpxx.get("taxincludedprice"));
                    try {
                        fp.setJshj_dx(new CurrencyUtil().toChinaUpper(fpxx.get("taxincludedprice")));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    fp.setBuy_name(fpxx.get("purchaser"));
                    fp.setBuy_tax_num(fpxx.get("purchasertaxno"));
                    fp.setBuy_bank_acc(xfxx.get("purchaserBank"));
                    fp.setBuy_add_tel(xfxx.get("purchaserAddress"));
                    fp.setJym(xfxx.get("checkCodeSix"));
                    fp.setTitle(extJson.getString("title"));
                    fp.setLoad_nsrsbh(fpxx.get("purchasertaxno"));// 录入税号 销售方纳税识别号
                    fp.setSapfph(sap_map.get("sapcode"));
                    fp.setSapkjnd(sap_map.get("nd"));
                    fp.setSapgsdm(sap_map.get("gsdm"));
                    fp.setSapfpjyr(sqr);// sap相关信息
                    fp.setRzbz(fpxx.get(""));// 入账备注
                    fp.setRzsm(fpxx.get(""));// 入账说明
                    fp.setXrsm(sm);// 税码
                    fp.setTax_rate(fpxx.get("taxrate"));// 税率
                    fp.setRzsj(sap_map.get("gzrq"));// 入账时间
                    fp.setCysj("0");// 查验时间
                    fp.setDk_qysh(fpxx.get(""));// 代开企业税号
                    fp.setDk_qymc(fpxx.get(""));// 代开企业名称
                    fp.setBz(fpxx.get(""));// 备注
                    fp.setMxslsfpp("0");
                    fp.setCycs("0");
                    String tpurl = "";
                    try {

                        String sourcePath = uu.getTempFile(fpxx.get("imageID") + "");
                        String url = "https://oss.xinri.com/attach/service/upload?bucket=oa-test";
                        File file = new File(sourcePath);
                        String result = uu.FilePost(url, file);
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>result=" + result + "<br/>");
                        tpurl = uu.Upload(fpxx.get("imageID"));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block

                    }
                    fp.setOcrfile(tpurl);// 发票路径
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>fp=" + fp + "<br/>");
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>payer=" + payer + "<br/>");
                    // 发票明细信息
                    List<Mxs> mxs = new ArrayList<Mxs>();
                    rs1.execute("select * from fnainvoiceledgerdetail where mainid=" + fpdm);
                    int hh = 1;
                    while (rs1.next()) {
                        String zd[] = {"id", "mainid", "invoiceServiceYype", "priceWithoutTax", "taxRate", "tax",
                                "unitNumber", "unitPrice", "originalUnitPrice", "specification", "unit", "unitPrice2",
                                "unitNumber2", "numberPlate", "type", "startDate", "endDate", "pricewithouttax"};
                        HashMap<String, String> map = new HashMap<String, String>();
                        for (int i = 0; i < zd.length; i++) {
                            map.put(zd[i], Util.null2String(rs1.getString(zd[i])));
                        }
//						bb.writeLog("map::" + map.toString() + "::::::::::::::::::::::::::::::");
//						bb.writeLog("..." + map.get("originalUnitPrice") + "....");
                        Mxs mx = new Mxs();
                        mx.setInv_code(fpxx.get("invoicecode"));
                        mx.setInv_num(fpxx.get("invoicenumber"));
                        mx.setLine_num("" + hh);
                        mx.setItem(map.get("invoiceServiceYype"));// 费用项目
                        mx.setType(map.get("specification"));// 规格型号
                        mx.setUnit(map.get("unit"));// 单位
                        if (map.get("unitNumber2").equals("")) {
                            mx.setAmount("0");
                        } else {
                            mx.setAmount(map.get("unitNumber2"));
                        }
                        if (map.get("originalUnitPrice").equals("")) {
                            mx.setPrice("0");
                        } else {
                            mx.setPrice(map.get("originalUnitPrice"));
                        }
                        if (map.get("pricewithouttax").equals("")) {
                            mx.setTotal_money("0");
                        } else {
                            mx.setTotal_money(map.get("pricewithouttax"));
                        }
                        mx.setTax_rate(map.get("taxrate"));//
                        if (map.get("tax").equals("")) {
                            mx.setTax_money("0");
                        } else {
                            mx.setTax_money(map.get("tax"));
                        }
                        mx.setSlbs(map.get(""));// 税率标识
                        mx.setTxrq_q(map.get("startDate"));//
                        mx.setTxrq_z(map.get("endDate"));//
                        mx.setCph(map.get(""));// 车牌号
                        mxs.add(mx);

                        hh++;
                    }
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>mxs=" + mxs + "<br/>");
                    // 当发票为机动车发票时必填
//					bb.writeLog("vehicleDetail" + vehicleDetail.toString() + ":::::");
                    if (fpxx.get("invoicetype").equals("12")) {
                        Jdcmx jdc = new Jdcmx();
                        rs1.execute("select * from motor_vehicleinvoice where mainid=" + fpdm);
                        rs1.next();
                        String zd[] = {"id", "mainid", "machine_code", "machine_number", "pretax_amount",
                                "seller_tax_id", "buyer_id", "tax_authorities", "tax_authorities_code", "car_code",
                                "car_engine_code", "car_model", "certificate_number"};
                        HashMap<String, String> map = new HashMap<String, String>();
                        for (int i = 0; i < zd.length; i++) {
                            map.put(zd[i], Util.null2String(rs1.getString(zd[i])));
                        }
                        jdc.setDw(map.get(""));// 吨位
                        try {
                            jdc.setCllx(vehicleDetail.getString("carType"));// 车辆类型

                            jdc.setFdjhm(map.get("car_engine_code"));// 发动机号码
                            jdc.setCjhm(map.get("car_code"));// 车架号码
                            jdc.setWspzhm(map.get(""));// 完税凭证号码
                            jdc.setSjdh(map.get(""));// 商检单号
                            jdc.setXcrs(vehicleDetail.getString("seatingCapacity"));// 限乘人数
                            jdc.setZzssl(extJson.getString("trate"));// 增值税税率
                            jdc.setCpxh(map.get("car_model"));// 厂牌型号
                            jdc.setHgzs(map.get("certificate_number"));// 合格证书
                            jdc.setSwjg_dm(map.get("tax_authorities_code"));// 税务机关代码
                            jdc.setSwjg_mc(map.get("tax_authorities"));// 税务机关名称
                            jdc.setCd(vehicleDetail.getString("origin"));// 产地
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        bill.setJdcmx(jdc);
                    }

                    bill.setFp(fp);

                    bill.setMxs(mxs);


                    net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(bill);
                    String jsonstr = json.toString();
                    if (jsonstr.indexOf("\"jdcmx\":null,") != -1) {
                        jsonstr = jsonstr.replaceAll("\"jdcmx\":null,", "");
                    }
                    // 将java对象转换为json对象
                    String str = "[" + jsonstr + "]";
                    out.print(">>>>>>>>测试页面>>>>>>>>>>>str=" + str + "<br/>");
                    try {
                        String result = su.testWebService(str, "http://10.10.11.101:8082/api/oa/zzsfpbc").toString();

                        out.print(">>>>>>>>测试页面>>>>>>>>>>>result=" + result + "<br/>");
                        if (result.indexOf("保存成功") != -1) {
                            rs.execute("update uf_fpxxlc set bs='" + result + "',sfybcswpt='1' where id=" + id);
                        } else {
                            rs.execute("update uf_fpxxlc set bs='" + result + "' where id=" + id);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>Exception<br/>");
                    }
                } else {// 非增值税
                    try {
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>非增值税发票<br/>");
                        JSONObject pr = products.getJSONObject(0);
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>"+pr+"<br/>");
                        // 发票信息
                        Bill_fzzs fp = new Bill_fzzs();
                        fp.setLot_no(lcbhpch);
                        fp.setQsr(qsr);
                        fp.setQssj(sj);
                        fp.setYwlx(ywlx);
                        fp.setFpzt("0");
                        fp.setSfocr("1");
                        fp.setQszt("1");
                        fp.setCode(fpxx.get("invoicecode"));
                        fp.setInv_num(fpxx.get("invoicenumber"));
                        fp.setKprq(fpxx.get("billingdate"));
                        fp.setFplx(setFplx1(fpxx.get("invoicetype")));

                        fp.setTotal(fpxx.get("pricewithouttax"));
                        fp.setSe(fpxx.get("tax"));
                        fp.setJshj(fpxx.get("taxincludedprice"));
                        fp.setKind(fpxx.get("kind"));
                        if (extJson.has("train_number")) {
                            fp.setTrain_number(extJson.getString("train_number"));
                        } else {
                            fp.setTrain_number("");
                        }
                        //
                        if (extJson.has("seat")) {
                            fp.setSeat(extJson.getString("seat"));
                        } else {
                            fp.setSeat("");
                        }
                        //
                        if (extJson.has("user_id")) {
                            fp.setUser_id(extJson.getString("user_id"));
                        }
                        if (extJson.has("name")) {
                            fp.setName(extJson.getString("name"));
                        } else if (extJson.has("user_name")) {
                            fp.setName(extJson.getString("user_name"));
                        } else {
                            fp.setName("");
                        }

                        fp.setFare(pr.getString("price"));
                        fp.setTax(pr.getString("tprice"));
                        rs1.execute("select * from fnainvoiceledgerdetail where mainid=" + fpdm);
                        rs1.next();
                        String zd[] = {"id", "mainid", "user_name", "user_id", "agentcode", "issue_by", "fare",
                                "fuel_surcharge", "caac_development_fund", "insurance"};
                        HashMap<String, String> map = new HashMap<String, String>();
                        for (int i = 0; i < zd.length; i++) {
                            map.put(zd[i], Util.null2String(rs1.getString(zd[i])));
                        }
                        fp.setFuel_surcharge(map.get("fuel_surcharge"));// 燃油附加费
                        fp.setCaac_development_fund(map.get("caac_development_fund"));// 民航发展基金
                        fp.setInsurance(map.get("insurance"));// 保险费
                        fp.setInternational_flag("");// 国际国内标签
                        fp.setBuyer(payer.getString("company"));
                        fp.setBuyer_tax_id(payer.getString("tcode"));

                        fp.setSapfph(sap_map.get("sapcode"));
                        fp.setSapkjnd(sap_map.get("nd"));
                        fp.setSapgsdm(sap_map.get("gsdm"));
                        fp.setSapfpjyr(sqr);// sap相关信息
                        fp.setXrsm(sm);// 税码
                        fp.setRzsj(sap_map.get("gzrq"));// 入账时间
                        String tpurl = "";
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>imageID=" + fpxx.get("imageID") + "<br/>");
                        try {

                            String sourcePath = uu.getTempFile(fpxx.get("imageID") + "");
                            String url = "https://oss.xinri.com/attach/service/upload?bucket=oa-test";
                            File file = new File(sourcePath);
                            String result = uu.FilePost(url, file);
                            out.print(">>>>>>>>测试页面>>>>>>>>>>>result=" + result + "<br/>");
                            tpurl = uu.Upload(fpxx.get("imageID"));
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                        }
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>tpurl=" + tpurl + "<br/>");
                        fp.setOcrfile(tpurl);// 发票路径
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>fp=" + fp + "<br/>");
                        net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(fp);
                        String jsonstr = json.toString();

                        // 将java对象转换为json对象
                        String str = "[" + jsonstr + "]";
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>str=" + str + "<br/>");
                        try {
                            String result = su.testWebService(str, "http://10.10.11.101:8082/api/oa/fzzspjbc")
                                    .toString();
                            out.print(">>>>>>>>测试页面>>>>>>>>>>>result:" + result + "<br/>");
                            if (result.indexOf("保存成功") != -1) {
                                rs.execute("update uf_fpxxlc set bs='" + result + "',sfybcswpt='1' where id=" + id);
                            } else {
                                rs.execute("update uf_fpxxlc set bs='" + result + "' where id=" + id);
                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                        }
                    } catch (Exception e) {
                        out.print(">>>>>>>>测试页面>>>>>>>>>>>接口异常<br/>");
                    }

                }
            }
        }


    } catch (Exception e) {
        e.printStackTrace();
    }
%>

<%!
    /**
     * 发票类型转换
     *
     * @param fplx
     * @return
     */
    private String setFplx(String fplx) {
        String newfplx = "";
        switch (fplx) {
            case "1":
                newfplx = "04";
                break;
            case "2":
                newfplx = "01";
                break;
            case "12":
                newfplx = "03";
                break;
            case "15":
                newfplx = "10";
                break;
            case "16":
                newfplx = "11";
                break;
            case "21":
                newfplx = "13";
                break;
            case "20":
                newfplx = "14";
                break;

        }
        return newfplx;
    }

    // 获取发票所有信息
    private HashMap<String, String> getAllFanInfo(String id) {
        HashMap<String, String> map = new HashMap<String, String>();
        RecordSet rs = new RecordSet();
        rs.execute("select * from fnainvoiceledger where id = " + id);
        rs.next();
        String zd[] = {"purchasertaxno", "salestaxno", "userid_new", "invoicesource_new", "checkcode", "status",
                "card_id_new", "encrypt_code_new", "openid_new", "wechatstatus", "id", "billingdate", "invoicecode",
                "invoicenumber", "invoicetype", "seller", "purchaser", "invoiceserviceyype", "pricewithouttax",
                "taxrate", "tax", "taxincludedprice", "authenticity", "reimbursementdate", "reimburseperson",
                "requestid", "entryTime", "company_seal", "form_type", "form_name", "kind", "ciphertext", "category",
                "imageID", "checkStatus", "updateOperate", "cloudId", "codeConfirm", "numberConfirm", "receiptor",
                "reviewer", "issuer", "province", "city", "travel_tax"};
        for (int i = 0; i < zd.length; i++) {
            map.put(zd[i], Util.null2String(rs.getString(zd[i])));
        }
        return map;
    }

    /**
     * 获取销方信息
     * 保存购买方信息、销售方信息、备注、校验码。由于受数据库单表字段总长度的限制，因此增加该表，该表和FnaInvoiceLedger位1对1的关系
     *
     * @param id
     * @return
     */
    private HashMap<String, String> getAllDtlInfo(String id) {
        HashMap<String, String> map = new HashMap<String, String>();
        RecordSet rs = new RecordSet();
        rs.execute("select * from FnaInvoiceLedgerDtl where mainid = " + id);
        rs.next();
        String zd[] = {"remark", "checkCodeSix", "sellerAddress", "purchaserAddress", "salesBank", "purchaserBank"};
        for (int i = 0; i < zd.length; i++) {
            map.put(zd[i], Util.null2String(rs.getString(zd[i])));
        }
        return map;
    }

    /**
     * 非增值税发票类型转换
     *
     * @param fplx
     * @return
     */
    private String setFplx1(String fplx) {
        String newfplx = "";
        switch (fplx) {
            case "7":
                newfplx = "1";
                break;
            case "8":
                newfplx = "2";
                break;
            case "10":
                newfplx = "3";
                break;
            case "14":
                newfplx = "4";
                break;
            case "3":
                newfplx = "5";
                break;
            case "9":
                newfplx = "6";
                break;

        }
        if (newfplx.equals("")) {
            newfplx = "7";
        }
        return newfplx;
    }

    /**
     * 从发票云平台获取所有相关信息
     *
     * @param fid
     * @return
     * @throws Exception
     */
    private JSONObject getAllInfoFromHttp(String fid,String token) {
        JSONObject data = new JSONObject();
        try {
            Soap_Util su = new Soap_Util();
            String params ="{ " + "    \"id\": \"" + fid + "\"" + "}";
           String objectStr =  sendOkHttpRequest(token,params);
//            String objectStr = su.testWebService("{ " + "    \"id\": \"" + fid + "\"" + "}",
//                    " https://api.mypiaojia.com/api/invoiceApi/invoice/get?token=" + token).toString();
            JSONObject jsonObject = new JSONObject(objectStr);
            data = jsonObject.getJSONObject("data");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;

    }

    private Map<String, String> getSAPInfo(String requestid) {
        Map<String, String> map = new HashMap<String, String>();
        RecordSet rs = new RecordSet();
        rs.execute(
                "select b.formid from workflow_requestbase a,workflow_base b where a.workflowid = b.id and a.requestid = "
                        + requestid);
        rs.next();
        int formid = Math.abs(rs.getInt("formid"));
        rs.execute("select * from formtable_main_" + formid + " where requestid =" + requestid);
        rs.next();
        String sapcode = Util.null2String(rs.getString("sapcode"));
        String gsdm = Util.null2String(rs.getString("gsdm"));
        String gzrq = Util.null2String(rs.getString("gzrq"));
        map.put("sapcode", sapcode);
        map.put("gsdm", gsdm);
        map.put("gzrq", gzrq);
        if (gzrq.length() > 4) {
            map.put("nd", gzrq.substring(0, 4));
        } else {
            map.put("nd", "");

        }
        return map;

    }

    private String getWorkcode(String id) {
        RecordSet rs = new RecordSet();
        rs.execute("select loginid from hrmresource where id =" + id);
        rs.next();
        return Util.null2String(rs.getString("loginid"));
    }

    private String sendOkHttpRequest(String token,String params){
        String result = "";
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, params);
            Request request = new Request.Builder()
                    .url("https://api.mypiaojia.com/api/invoiceApi/invoice/get?token="+token)
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
            result = response.body().string();
        }catch (Exception e){
            e.printStackTrace();
        }
       return result;
    }
%>




